<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('预约教练-学员预约界面')" />
</head>
<body class="gray-bg">
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<!-- <li>
								教练名：<input type="text" name="coachName"/>
							</li>

							<li>
								手机号：<input type="text" name="coachPhone"/>
							</li> -->

							<li class="select-time">
							    <label>时间： </label>
							    <!-- getNowDay是自己实现的方法，写在common.js里 -->
							    <input type="text" class="time-input" id="startTime" data-init="getNowDay" placeholder="选择时间" name="beginTime" />
							</li>


							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
					
					<input type="hidden" id="phone" th:value="${phone}" name="phone">
					<input type="hidden" id="name" th:value="${name}" name="name">
				</form>
			</div>
			
	        <!-- <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:coachPlan:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="system:coachPlan:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:coachPlan:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:coachPlan:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div> -->
			<div class="col-sm-12 select-table table-striped table-bordered">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:coachPlan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:coachPlan:remove')}]];
        var prefix = ctx + "system/reservation";


        $(function() {
            var options = {
                url: prefix + "/traineeReserveList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				onClickCell: onClickCell,
                modalName: "预约计划",
		        showExport: false,
		        
		        
                columns: [{
		            checkbox: true
		        },
				/* {
					field : 'coachplanId', 
					title : 'id',
					sortable: true
				}, */
				{
					field : 'coachName', 
					title : '教练名'
				},
				/* {
					field : 'coachPhone', 
					title : '手机号'
					
				}, */
				{
					field : 'date', 
					title : '时间'
				},
				{
					field : 'week', 
					title : ''
				},
				{
					field : 'time8', 
					title : '08~09时',
					formatter : function showStatu(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
			        
			        }
					
				},
				{
					field : 'time9', 
					title : '09~10时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					} 
				},
				{
					field : 'time10', 
					title : '10~11时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time11', 
					title : '11~12时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time12', 
					title : '12~13时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time13', 
					title : '13~14时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time14', 
					title : '14~15时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time15', 
					title : '15~16时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time16', 
					title : '16~17时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time17', 
					title : '17~18时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time18', 
					title : '18~19时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				},
				{
					field : 'time19', 
					title : '19~20时',
					formatter : function(value,row,index){
						if(value==0){
							return '<a class="btn btn-danger btn-xs btn-block disabled">已约满</a>';
						}else if (value>0){
				        	 
				        	　return '<button class="btn btn-primary btn-xs btn-block">可预约</button>';
			        	}
						//已预约优先显示
						if(value == -2){
							return '<a class="btn btn-success btn-xs btn-block disabled">已预约</a>';
						}
						
					}
				}, 
				
		        /* {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.coachplanId + '\')" shiro:hasPermission="system:coachPlan:edit"><i class="fa fa-edit"></i>取消预约</a> ');
						return actions.join('');
		            }
		        } */ ]
            };
            $.table.init(options);
        });
        
        function onClickCell(field, value, row, $element){
        	//单击表格预约
        	if(field=='time8'||field=='time9'||field=='time10'||field=='time11'
        			||field=='time12'||field=='time13'||field=='time14'||field=='time15'
        			||field=='time16'||field=='time17'||field=='time18'||field=='time19'){
        		if(value>0){
        			
       				var	coachName = row.coachName;//教练名
               		var	coachPhone = row.coachPhone;//教练手机号
       	        	var	date = row.date;//yyyy-MM-dd选定时间
       	        	var	timeValue = field;//通过time?来获取到点击的是几时的预约
       	        	var phone = $("#phone").val();
       	        	var name = $("#name").val();
	        				
        			
        			//---------------------------
        			layer.confirm(
        					"确认预约"+name+"？",
        					{icon: 3, title:'提示'},
        					function(index){
        						$.ajax({
        	        				//去预约点击的这个教练
        	                		type: "POST",
        	                		data: {
        	                			coachName: row.coachName,
        	                			coachPhone: row.coachPhone,
        	        	        		date: row.date,//yyyy-MM-dd
        	        	        		timeValue: field,//通过time?来获取到点击的是几时的预约
        	        	        		phone: phone
        	                		},
        	                		dateType: "json",
        	                		url: prefix + "/add",
        	                		beforeSend: function () {
        	            	        	$.modal.loading("正在处理中，请稍后...");
        	            	        },
        	            	        success: function(result) {
        	            	        	
        	            	        	$.operate.ajaxSuccess(result);
        	            	        }
        	                	})
        					}
        			);
        			
        		}
        		
        		//如果是已预约(-2)状态点击，是取消预约
        		if(value == -2){
        			layer.confirm(
        					"是否取消预约？",
        					{icon: 5, title:'提示'},
        					function call(){
        						$.ajax({
        	        				//去预约点击的这个教练
        	                		type: "POST",
        	                		data: {
        	                			coachName: row.coachName,
        	                			coachPhone: row.coachPhone,
        	        	        		date: row.date,//yyyy-MM-dd
        	        	        		timeValue: field,//通过time?来获取到点击的是几时的预约
        	        	        		phone: phone
        	                		},
        	                		dateType: "json",
        	                		url: prefix + "/clickCancel",
        	                		beforeSend: function () {
        	            	        	$.modal.loading("正在处理中，请稍后...");
        	            	        },
        	            	        success: function(result) {
        	            	        	
        	            	        	$.operate.ajaxSuccess(result);
        	            	        }
        	                	})
        					}
        			);
        		}
        		
        	}
        	
        }
        
        
        
    </script>
</body>
</html>